Skip to content

Conversation

N1ebieski
Copy link
Contributor

This PR adds position range for MethodCall context.

This PR is neccessary for laravel/vs-code-extension#462. If laravel/vs-code-extension#462 will be rejected, this PR can be closed.

Before:

./php-parser detect "<?php
> 
> use App\Models\Example;
> 
> Example::query()
>     ->popular()
>     ->active()
>     ->get();
> " --debug

================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <?php use App\Models\Example; Example::query() ->p
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <?php 
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser

 Microsoft\PhpParser\Node\Statement\NamespaceUseDeclaration use App\Models\Example;
  Microsoft\PhpParser\Node\DelimitedList\NamespaceUseClauseList App\Models\Example
   Microsoft\PhpParser\Node\NamespaceUseClause App\Models\Example
    Microsoft\PhpParser\Node\QualifiedName App\Models\Example
 Microsoft\PhpParser\Node\Statement\ExpressionStatement Example::query() ->popular() ->active() ->get();
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\ExpressionStatementParser

  Microsoft\PhpParser\Node\Expression\CallExpression Example::query() ->popular() ->active() ->get()
  + Context: App\Contexts\MethodCall
  * Parsing: App\Parsers\CallExpressionParser

   Microsoft\PhpParser\Node\Expression\MemberAccessExpression Example::query() ->popular() ->active() ->get
   + Context: App\Contexts\MethodCall
   * Parsing: App\Parsers\MemberAccessExpressionParser

    Microsoft\PhpParser\Node\Expression\CallExpression Example::query() ->popular() ->active()
    + Context: App\Contexts\MethodCall
    * Parsing: App\Parsers\CallExpressionParser

     Microsoft\PhpParser\Node\Expression\MemberAccessExpression Example::query() ->popular() ->active
     + Context: App\Contexts\MethodCall
     * Parsing: App\Parsers\MemberAccessExpressionParser

      Microsoft\PhpParser\Node\Expression\CallExpression Example::query() ->popular()
      + Context: App\Contexts\MethodCall
      * Parsing: App\Parsers\CallExpressionParser

       Microsoft\PhpParser\Node\Expression\MemberAccessExpression Example::query() ->popular
       + Context: App\Contexts\MethodCall
       * Parsing: App\Parsers\MemberAccessExpressionParser

        Microsoft\PhpParser\Node\Expression\CallExpression Example::query()
        + Context: App\Contexts\MethodCall
        * Parsing: App\Parsers\CallExpressionParser

         Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression Example::query
         + Context: App\Contexts\MethodCall
         * Parsing: App\Parsers\ScopedPropertyAccessExpressionParser

          Microsoft\PhpParser\Node\QualifiedName Example
[
    {
        "type": "methodCall",
        "methodName": "get",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        }
    },
    {
        "type": "methodCall",
        "methodName": "active",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        }
    },
    {
        "type": "methodCall",
        "methodName": "popular",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        }
    },
    {
        "type": "methodCall",
        "methodName": "query",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        }
    }

After:

./php-parser detect "<?php

use App\Models\Example;

Example::query()
    ->popular()
    ->active()
    ->get();
" --debug

================================================================================
================================================================================
                              STARTING TO PARSE
================================================================================
================================================================================

Microsoft\PhpParser\Node\SourceFileNode <?php use App\Models\Example; Example::query() ->p
+ Context: App\Contexts\Base
* Parsing: App\Parsers\SourceFileNodeParser

 Microsoft\PhpParser\Node\Statement\InlineHtml <?php 
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\InlineHtmlParser

 Microsoft\PhpParser\Node\Statement\NamespaceUseDeclaration use App\Models\Example;
  Microsoft\PhpParser\Node\DelimitedList\NamespaceUseClauseList App\Models\Example
   Microsoft\PhpParser\Node\NamespaceUseClause App\Models\Example
    Microsoft\PhpParser\Node\QualifiedName App\Models\Example
 Microsoft\PhpParser\Node\Statement\ExpressionStatement Example::query() ->popular() ->active() ->get();
 + Context: App\Contexts\Base
 * Parsing: App\Parsers\ExpressionStatementParser

  Microsoft\PhpParser\Node\Expression\CallExpression Example::query() ->popular() ->active() ->get()
  + Context: App\Contexts\MethodCall
  * Parsing: App\Parsers\CallExpressionParser

   Microsoft\PhpParser\Node\Expression\MemberAccessExpression Example::query() ->popular() ->active() ->get
   + Context: App\Contexts\MethodCall
   * Parsing: App\Parsers\MemberAccessExpressionParser

    Microsoft\PhpParser\Node\Expression\CallExpression Example::query() ->popular() ->active()
    + Context: App\Contexts\MethodCall
    * Parsing: App\Parsers\CallExpressionParser

     Microsoft\PhpParser\Node\Expression\MemberAccessExpression Example::query() ->popular() ->active
     + Context: App\Contexts\MethodCall
     * Parsing: App\Parsers\MemberAccessExpressionParser

      Microsoft\PhpParser\Node\Expression\CallExpression Example::query() ->popular()
      + Context: App\Contexts\MethodCall
      * Parsing: App\Parsers\CallExpressionParser

       Microsoft\PhpParser\Node\Expression\MemberAccessExpression Example::query() ->popular
       + Context: App\Contexts\MethodCall
       * Parsing: App\Parsers\MemberAccessExpressionParser

        Microsoft\PhpParser\Node\Expression\CallExpression Example::query()
        + Context: App\Contexts\MethodCall
        * Parsing: App\Parsers\CallExpressionParser

         Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression Example::query
         + Context: App\Contexts\MethodCall
         * Parsing: App\Parsers\ScopedPropertyAccessExpressionParser

          Microsoft\PhpParser\Node\QualifiedName Example
[
    {
        "type": "methodCall",
        "methodName": "get",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        },
        "start": {
            "line": 4,
            "column": 0
        },
        "end": {
            "line": 7,
            "column": 11
        }
    },
    {
        "type": "methodCall",
        "methodName": "active",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        },
        "start": {
            "line": 4,
            "column": 0
        },
        "end": {
            "line": 6,
            "column": 14
        }
    },
    {
        "type": "methodCall",
        "methodName": "popular",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        },
        "start": {
            "line": 4,
            "column": 0
        },
        "end": {
            "line": 5,
            "column": 15
        }
    },
    {
        "type": "methodCall",
        "methodName": "query",
        "className": "App\\Models\\Example",
        "arguments": {
            "type": "arguments",
            "autocompletingIndex": 0,
            "children": []
        },
        "start": {
            "line": 4,
            "column": 0
        },
        "end": {
            "line": 4,
            "column": 16
        }
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant